package com.zhongshengnetwork.rightbe.lang.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
//import android.support.annotation.NonNull;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

import com.zhongshengnetwork.rightbe.Constant.APIKey;
import com.zhongshengnetwork.rightbe.CustomApplication;
import com.zhongshengnetwork.rightbe.R;
import com.zhongshengnetwork.rightbe.common.CommonUtils;
import com.zhongshengnetwork.rightbe.common.TopBarView;
import com.zhongshengnetwork.rightbe.common.activity.AppBaseActivity;
import com.zhongshengnetwork.rightbe.lang.view.CareOrFansFragment;

import java.util.Map;

public class FansActivity extends AppBaseActivity implements TopBarView.onTitleBarClickListener{
    public static final String KEY_USER_ID = "user_id";
    public static final String KEY_SOURCE_ID = "source_id";

    private TopBarView topbar;
    private UserFansFragment fansFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fans);
        topbar = (TopBarView)findViewById(R.id.topbar);
        topbar.getRightView().setVisibility(View.GONE);
        topbar.setClickListener(this);
        topbar.getRightTextView().setVisibility(View.GONE);
        Intent intent = getIntent();
        if (intent != null && intent.hasExtra(TopBarView.KEY_TITLE)) {
            topbar.getTitleView().setText(intent.getStringExtra(TopBarView.KEY_TITLE));
        }

        fansFragment = new UserFansFragment();
        if (intent != null) {
            fansFragment.setSourceId(intent.getStringExtra(KEY_SOURCE_ID));
            fansFragment.setUserId(intent.getStringExtra(KEY_USER_ID));
            fansFragment.setType(intent.getIntExtra(APIKey.typeKey,0));
        }
        getSupportFragmentManager().beginTransaction().add(R.id.fans_container, fansFragment).commit();
    }

    /**
     * 点击了返回导航按钮
     */
    @Override
    public void onBackClick() {
        //Toast.makeText(LoginActivity.this, "你点击了左侧按钮", Toast.LENGTH_LONG).show();
        hintKeyBoard();
        finish();
    }

    /**
     * 点击了右边导航按钮
     */
    @Override
    public void onRightClick() {

    }



    public void hintKeyBoard() {
        //拿到InputMethodManager
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        //如果window上view获取焦点 && view不为空
        if (imm.isActive() && getCurrentFocus() != null) {
            //拿到view的token 不为空
            if (getCurrentFocus().getWindowToken() != null) {
                //表示软键盘窗口总是隐藏，除非开始时以SHOW_FORCED显示。
                imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            }
        }
    }

    public static class UserFansFragment extends CareOrFansFragment {

        private String userId;
        private String sourceId;
        private int type;

        public String getUserId() {
            return userId;
        }

        public void setUserId(String userId) {
            this.userId = userId;
        }

        public String getSourceId() {
            return sourceId;
        }

        public void setSourceId(String sourceId) {
            this.sourceId = sourceId;
        }

        public int getType() {
            return type;
        }

        public void setType(int type) {
            this.type = type;
        }

        @Override
        protected Map<String, String> getHttpParams() {
            Map<String, String> params = super.getHttpParams();
            if (type == 1){
                if (CommonUtils.isLogin() == true){
                    params.put(APIKey.tokenKey, CustomApplication.loginModel.getToken());
                }
                params.put("dataId", sourceId);
                params.put("pageIndex", pageindex+"");
                params.put("pageRecord",Records+"");
            }else {
                params.put(APIKey.typeKey,"0");
                params.put("sourceid", sourceId);
                params.put("pageindex",pageindex+"");
                params.put("pagerecords",Records+"");
            }
            return params;
        }

        @Override
        protected String getHttpPath() {
            if (type == 1){
                return "weishu/content/like/list.do";
            }
            return "miniapp/langappid/getlanguser.do";
        }
    }

}
